# xmas_scan.py
from scapy.all import *

# 扫描单个端口
def xmas_scan(ip, port):
    src_port = RandShort()  # 随机源端口
    xmas_packet = IP(dst=ip)/TCP(sport=src_port, dport=port, flags="FPU")  # 创建Xmas包
    response = sr1(xmas_packet, timeout=1, verbose=False)  # 发送Xmas包并等待响应

    if response:
        if response.haslayer(TCP):
            if response.getlayer(TCP).flags == 0x14:  # RST响应
                print(f"Port {port} is closed on {ip}")
    else:
        print(f"Port {port} is open or filtered on {ip}")

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: python3 xmas_scan.py <ip> <port> ")
        sys.exit(1)
    ip = sys.argv[1]
    port = int(sys.argv[2])
    xmas_scan(ip, port)

# pip install scapy
# sansjtw